home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / BSP Tree 1.2 / Sources / Graphics / source / vector_2d.cp < prev    next >
Encoding:
Text File  |  1995-03-25  |  3.5 KB  |  93 lines  |  [TEXT/MMCC]

  1. //------------------------------------------------------------------------------
  2. //    File:                    vector_2d.cp
  3. //    Date:                    1/21/95
  4. //    Author:                Bretton Wade
  5. //
  6. //    Description:    this file contains the methods for a 2d vector_3d
  7. //
  8. //------------------------------------------------------------------------------
  9.  
  10. #include "point_2d.h"
  11. #include "vector_2d.h"
  12.  
  13. //------------------------------------------------------------------------------
  14. //    constructor
  15. //------------------------------------------------------------------------------
  16. vector_2d::vector_2d (real x, real y) : tuple_2d (x, y)                                                    //    constructor from 2 values
  17. {
  18. }
  19.  
  20. //------------------------------------------------------------------------------
  21. //    constructor
  22. //------------------------------------------------------------------------------
  23. vector_2d::vector_2d (const vector_2d &v) : tuple_2d (v)                                                //    copy constructor
  24. {
  25. }
  26.  
  27. //------------------------------------------------------------------------------
  28. //    constructor
  29. //------------------------------------------------------------------------------
  30. vector_2d::vector_2d (const point_2d &p) : tuple_2d (p)                                                    //    constructor from a point
  31. {
  32. }
  33. //------------------------------------------------------------------------------
  34. //    assignment operator
  35. //------------------------------------------------------------------------------
  36. vector_2d    &vector_2d::operator = (const vector_2d &v)                                                        //    assignment operator
  37. {
  38.     tuple_2d::operator = (v);
  39.     return *this;
  40. }
  41.  
  42. //------------------------------------------------------------------------------
  43. //    multiply a vector_3d by a scalar
  44. //------------------------------------------------------------------------------
  45. vector_2d    vector_2d::operator * (real s) const                                                                    //    scalar multiplication
  46. {
  47.     return vector_2d (xy[X] * s, xy[Y] * s);
  48. }
  49.  
  50. //------------------------------------------------------------------------------
  51. //    divide a vector_3d by a scalar
  52. //------------------------------------------------------------------------------
  53. vector_2d    vector_2d::operator / (real s) const                                                                    //    scalar division
  54. {
  55.     return vector_2d (xy[X] * s, xy[Y] * s);
  56. }
  57.  
  58. //------------------------------------------------------------------------------
  59. //    add two vectors
  60. //------------------------------------------------------------------------------
  61. vector_2d    vector_2d::operator + (const vector_2d &v) const                                            //    addition operator
  62. {
  63.     return vector_2d (xy[X] + v[X], xy[Y] + v[Y]);
  64. }
  65.  
  66. //------------------------------------------------------------------------------
  67. //    subtract two vectors
  68. //------------------------------------------------------------------------------
  69. vector_2d    vector_2d::operator - (const vector_2d &v) const                                            //    subtraction operator
  70. {
  71.     return vector_2d (xy[X] - v[X], xy[Y] - v[Y]);
  72. }
  73.  
  74. //------------------------------------------------------------------------------
  75. //    compute the length of the vector_3d
  76. //------------------------------------------------------------------------------
  77. real            vector_2d::Norm (void) const                                                                                    //    compute the length of the vector_2d
  78. {
  79.     return sqrt ((xy[X] * xy[X]) + (xy[Y] * xy[Y]));
  80. }
  81.  
  82. //------------------------------------------------------------------------------
  83. //    normalize the vector_3d
  84. //------------------------------------------------------------------------------
  85. vector_2d    &vector_2d::Normalize (void)                                                                                    //    reduce the vector_2d to length 1.0
  86. {
  87.     real    length = Norm ();
  88.     xy[X] /= length; xy[Y] /= length;
  89.     return *this;
  90. }
  91.  
  92. //------------------------------------------------------------------------------
  93.